package com.qpf.mycms.component.auth.service;

import com.qpf.mycms.api.SysUserServiceApi;
import com.qpf.mycms.api.pojo.dto.UserDto;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SysUserDetailsService implements UserDetailsService {
    @Resource
    private SysUserServiceApi sysUserServiceApi;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserDto userDto = sysUserServiceApi.findUserByAccount(username);
        return new User(username, userDto.getPassword(), AuthorityUtils.commaSeparatedStringToAuthorityList("ADMIN"));
    }
}
